package com.dxtx.util;

import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;

public class CircleColorDrawable extends Drawable {

    private Paint mPaint;
    private int mRange;
    private int color;

    private float mDrawablePadding;


    public CircleColorDrawable(int color) {
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setColor(color);
//        mRange = Math.min(bitmap.getWidth(), bitmap.getHeight());

        //获取centerCrop的源位置,长宽不统一则放弃一部分
    }

    public CircleColorDrawable(int color, float drawablePadding) {
        this(color);
        this.mDrawablePadding = drawablePadding;
    }

    @Override
    public void draw(Canvas canvas) {
//        canvas.drawCircle(mRange / 2, mRange / 2, mRange / 2, mPaint);
        Rect r = getBounds();
        canvas.drawOval(new RectF(r), mPaint);
    }

    @Override
    public int getIntrinsicWidth() {
        return mRange;
    }

    @Override
    public int getIntrinsicHeight() {
        return mRange;
    }

    @Override
    public void setAlpha(int alpha) {
        mPaint.setAlpha(alpha);
    }

    @Override
    public void setColorFilter(ColorFilter cf) {
        mPaint.setColorFilter(cf);
    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }

    @Override
    protected void onBoundsChange(Rect bounds) {
        mRange = bounds.width();
    }

    public void setColor(int color) {
        this.color = color;
        mPaint.setColor(color);
    }
}
